<?php


namespace Tools;


/**
 * 字符串工具
 * Class StringTool
 *
 * @package Tools
 */
class StringTool
{

    /**
     * 判断是否为 json
     *
     * @param string $str
     * @param bool   $returnDecoded
     *
     * @return mixed
     */
    public static function isJsonStrict(string $str, bool $returnDecoded = false)
    {
        $decoded = json_decode($str, true);
        if (json_last_error() !== JSON_ERROR_NONE) {
            return false;
        }
        return $returnDecoded ? $decoded : true;
    }

}